package com.xbongbong.pro.statistic.help;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.PaasFormRefEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.enums.AddressEnum;
import com.xbongbong.paas.enums.AggTypeEnum;
import com.xbongbong.paas.enums.BIProductEnum;
import com.xbongbong.paas.enums.BIProductReformEnum;
import com.xbongbong.paas.enums.BISubProductCommonFieldEnum;
import com.xbongbong.paas.enums.BISubProductFieldEnum;
import com.xbongbong.paas.enums.ComboTypeEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.paas.enums.UnitEnum;
import com.xbongbong.paas.enums.bi.DataSetFieldStatusEnum;
import com.xbongbong.paas.enums.clazz.AggsTypeClass;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.paas.help.FormExplainHelp;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.PaasFormRefModel;
import com.xbongbong.paas.pojo.FormExplainPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CloneUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.constant.SymbolConstant;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.IntervalTypeEnum;
import com.xbongbong.pro.enums.LeaveMarksEnum;
import com.xbongbong.pro.enums.PaasStageEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.statistic.constant.RelatedProductConstant;
import com.xbongbong.pro.statistic.enums.ChartAttrTypeEnum;
import com.xbongbong.pro.statistic.enums.ChartTypeEnum;
import com.xbongbong.pro.statistic.pojo.ChartFieldAttrPojo;
import com.xbongbong.pro.statistic.pojo.SlaveSourcePojo;
import com.xbongbong.pro.statistic.pojo.SpecialFieldPojo;
import com.xbongbong.pro.statistic.pojo.WidgetSelectPojo;
import com.xbongbong.pro.statistic.pojo.vo.DataSourceAttrVO;
import com.xbongbong.pro.statistic.pojo.vo.DataSourceObjectVO;
import com.xbongbong.pro.statistic.service.ChartLimitService;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.NumberTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.base.CommunicateBaseEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.ContractPerformanceEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.product.ContractProductBIEnum;
import com.xbongbong.saas.enums.product.ContractProductEnum;
import com.xbongbong.saas.enums.subform.ContractPerformanceSubFormEnum;
import com.xbongbong.saas.util.FundUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 图表获取字段帮助类
 * @ClassName ChartAttrHelp
 * @Author 梁鲁江
 * 创建时间 2022/9/5 20:06
 * 修改时间  2022/9/5 20:06
 **/
@Component
public class ChartAttrHelp {
    private static final Logger LOG = LoggerFactory.getLogger(ChartAttrHelp.class);
    @Resource
    private ProFormHelp proFormHelp;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PaasFormRefModel paasFormRefModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private FormExplainHelp formExplainHelp;
    @Resource
    private ChartLimitService chartLimitService;
    
    public ChartFieldAttrPojo commonDataSourceAttrEnclosure(FieldAttrEntity fieldAttrEntity, Integer businessType, String corpid, Long formId) throws XbbException {
        getItems(fieldAttrEntity, businessType, corpid, formId);
        ChartFieldAttrPojo chartFieldAttrPojo = new ChartFieldAttrPojo();
        BeanUtil.copyProperties(fieldAttrEntity,chartFieldAttrPojo);
        return chartFieldAttrPojo;
    }

    /**
     * 获取解释中的Items (签订人类型 items注入)
     * @param fieldAttrEntity 字段属性
     * @author zhouwq
     * @date 2019/6/27 10:39
     */
    public void getItems(FieldAttrEntity fieldAttrEntity, Integer businessType, String corpid, Long formId) throws XbbException {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        String saasAttr = fieldAttrEntity.getSaasAttr();

        //资金账户对应saasAttr
        List<String> fundAccountSaasAttrList = FundUtil.getFundAccountSaasAttrList();
        if(Objects.equals(ContractPerformanceEnum.IS_SIGN.getSaasAttr(),saasAttr)){
            //是否为签订人
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setValue(0);
            itemPoJo.setText(I18nMessageUtil.getMessage(CommonConstant.NO));
            itemPoJos.add(itemPoJo);
            ItemPoJo itemPoJoNew = new ItemPoJo();
            itemPoJoNew.setValue(1);
            itemPoJoNew.setText(I18nMessageUtil.getMessage(CommonConstant.YES));
            itemPoJos.add(itemPoJoNew);
        } else if (fundAccountSaasAttrList.contains(saasAttr)) {
            itemPoJos = proFormHelp.handleFundAccountItems(corpid, businessType);
        } else {
            itemPoJos = proFormHelp.getItem(fieldAttrEntity, businessType, corpid, formId);
        }

        if(itemPoJos.size()>0) {
            fieldAttrEntity.setItems(itemPoJos);
        }
    }

    /**
     * 关联字段处理
     * @param fieldAttrEntity 字段属性
     * @param corpId 公司ID
     * @param linkedNames 关联字段名称集合 因单表内关联字段名称唯一可判断该数据源存在几个关联数据字段
     * @param dataSourceAttrVO  字段返回对象
     * @param linkedSourceNames 该数据源已添加的关联字段名称
     * @throws XbbException error
     * @author zhouwq
     * @date 2019/6/27 14:30
     */
    public void linkedDataAttrHandle(FieldAttrEntity fieldAttrEntity, String corpId, List<String> linkedNames, DataSourceAttrVO dataSourceAttrVO,
                                      List<String> linkedSourceNames, Integer chartType) throws XbbException {
        LinkInfoPojo linkInfoPojo = fieldAttrEntity.getLinkInfo();
        Long linkFormId = linkInfoPojo.getLinkFormId();
        if (linkFormId != null) {
            PaasFormEntityExt paasFormEntityExt;
            //工单不入关联数据选择项中
            if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), linkInfoPojo.getLinkBusinessType())) {
                return;
            } else {
                paasFormEntityExt = paasFormModel.getByKey(linkFormId, corpId);
            }
            if (Objects.isNull(paasFormEntityExt)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_NOT_EXIST);
            }
            SlaveSourcePojo sourcePojo = new SlaveSourcePojo();
            BeanUtil.copyProperties(paasFormEntityExt, sourcePojo);
            sourcePojo.setFormId(linkFormId);
            sourcePojo.setName(fieldAttrEntity.getAttrName());
            sourcePojo.setLinkAttr("dataId");
            List<String> nameList = new ArrayList<>();
            nameList.add(fieldAttrEntity.getAttrName());
            linkedNames.add(fieldAttrEntity.getAttrName());
            sourcePojo.setLinkedSourceName(nameList);
            sourcePojo.setDriveLinkedAttr(fieldAttrEntity.getAttr());
            //关联数据中 slaveSource默认dataId fieldType 为0
            sourcePojo.setFieldType(0);
            dataSourceAttrVO.addSlaveSources(sourcePojo);
            if (linkedSourceNames != null && linkedSourceNames.contains(fieldAttrEntity.getAttrName())) {
                List<LinkedAttrPoJo> fieldAttrs = linkInfoPojo.getLinkedAttr();
                List<FieldAttrEntity> linkedFieldAttrEntities = new ArrayList<>();
                try {
                    BeanUtil.copyPropertiesList(fieldAttrs, linkedFieldAttrEntities, FieldAttrEntity.class);
                } catch (Exception e) {
                    LOG.error("copyPropertiesList error", e);
                }
                sourcePojo.setName(fieldAttrEntity.getAttrName());
                //关联数据中的字段进行字段过滤
                setDataSourceAttrVO(dataSourceAttrVO, corpId, sourcePojo, linkedFieldAttrEntities, 0, null, chartType);
            }
        }
    }

    /**
     * 处理产品子表单的表单解释
     *
     * @param subFormList
     * @param subForm
     * @param formId
     * @param paasFormRefEntity
     */
    public void handleSubProductFieldList(List<FieldAttrEntity> subFormList, SubFormPoJo subForm, Long formId, PaasFormRefEntity paasFormRefEntity) {
        Integer subProductBusinessType = paasFormRefEntity.getBusinessType();
        Integer type = paasFormRefEntity.getType();
        BIProductReformEnum biProductReformEnum = BIProductReformEnum.getBiProductReformByType(subProductBusinessType, type);
        List<String> shouldRemoveAttrs = BISubProductFieldEnum.getFieldListBySubProductBus(subProductBusinessType, type);
        FieldAttrEntity productSerialNoFieldAttr = new FieldAttrEntity();
        BeanUtil.copyProperties(BISubProductCommonFieldEnum.PRODUCT_NO, productSerialNoFieldAttr);
        //subFormList.add(productSerialNoFieldAttr);
        subFormList.addAll(subForm.getItems());
        boolean shouldRemoveTag = CollectionsUtil.isEmpty(shouldRemoveAttrs) ? false : true;
        Iterator<FieldAttrEntity> fieldAttrEntityIterator = subFormList.iterator();
        while (fieldAttrEntityIterator.hasNext()) {
            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
            if (shouldRemoveTag && shouldRemoveAttrs.contains(fieldAttrEntity.getAttr())) {
                fieldAttrEntityIterator.remove();
                continue;
            }
            //兼容经销商业务
            if (Objects.equals(biProductReformEnum, BIProductReformEnum.CONTRACT_PRODUCT) ) {
                if (Objects.equals(fieldAttrEntity.getSaasAttr(), ContractProductEnum.SHIPMENTS_NUM.getSaasAttr())
                        || Objects.equals(fieldAttrEntity.getSaasAttr(), ContractProductEnum.PROMOTION.getSaasAttr())) {
                    fieldAttrEntityIterator.remove();
                    continue;
                }
            }
            fieldAttrEntity.setFormId(formId);
            if (Objects.equals(fieldAttrEntity.getAttr(), biProductReformEnum.getSubLinkProductAttr())) {
                BISubProductCommonFieldEnum biSubProductCommonFieldEnum = BISubProductCommonFieldEnum.PRODUCT_NAME;
                BeanUtil.copyProperties(biSubProductCommonFieldEnum, fieldAttrEntity);
            }
            //只要是产品子表单，那么这边统一处理parentAttr为null,因为后面很多不同的地方默认都是把有parentAttr作为子表单去做查询
            fieldAttrEntity.setParentAttr(null);
        }
    }

    /**
     * 排除下拉自定外的项
     * @param fieldAttrEntity
     * @return
     */
    private  boolean linkFilterCombo(FieldAttrEntity fieldAttrEntity) {
        return ComboTypeEnum.LINKFORM.getType().equals(fieldAttrEntity.getComboType()) || ComboTypeEnum.DATARELY.getType().equals(fieldAttrEntity.getComboType()) || ComboTypeEnum.BUSINESS.getType().equals(fieldAttrEntity.getComboType());
    }

    /**
     * 设置字段关键信息
     * @param fieldTypeEnum
     * @return
     */
    private ChartFieldAttrPojo  setAttrField(FieldTypeEnum fieldTypeEnum,SlaveSourcePojo slaveSourcePojo) {
        ChartFieldAttrPojo chartFieldAttrPojo = new ChartFieldAttrPojo();
        chartFieldAttrPojo.setFieldType(fieldTypeEnum.getType());
        chartFieldAttrPojo.setAttr((fieldTypeEnum.getAlias()));
        chartFieldAttrPojo.setAttrName(fieldTypeEnum.getDescription());
        chartFieldAttrPojo.setAttrType(fieldTypeEnum.getEsalias());
        if(Objects.nonNull(slaveSourcePojo)){
            chartFieldAttrPojo.setFormId(slaveSourcePojo.getFormId());
            chartFieldAttrPojo.setBusinessType(slaveSourcePojo.getBusinessType());
        }
        return  chartFieldAttrPojo;
    }
    
    /**
     * 设置待选字段
     *
     * @param dataSourceAttrVO 入参
     * @param corpid           公司id
     * @param slaveSourcePojo           数据源
     * @param fieldAttrEntities     关联数据的字段
     * @param single     判断单表/多表
     * @throws XbbException 异常
     */
    public void setDataSourceAttrVO(DataSourceAttrVO dataSourceAttrVO, String corpid, SlaveSourcePojo slaveSourcePojo, List<FieldAttrEntity> fieldAttrEntities,
                                     Integer single, List<SlaveSourcePojo> sources, Integer chartType) throws XbbException {
        //可展示字段，表头/穿透
        DataSourceObjectVO showDataSourceObjectVO = new DataSourceObjectVO();
        //可筛选的    paasFormExplainService.screenList
        DataSourceObjectVO selectDataSourceObjectVO = new DataSourceObjectVO();
        //分组/分类字段
        DataSourceObjectVO groupDataSourceObjectVO = new DataSourceObjectVO();
        //查询表可汇总的
        DataSourceObjectVO summaryDataSourceObjectVO = new DataSourceObjectVO();
        //仪表盘需要的字段
        DataSourceObjectVO dashboardSourceObjectVO = new DataSourceObjectVO();
        //统计表可汇总的
        DataSourceObjectVO querySummaryDataSourceObjectVo = new DataSourceObjectVO();
        //归属人
        DataSourceObjectVO belongDataSourceObjectVO = new DataSourceObjectVO();
        //时间类型
        DataSourceObjectVO timeDataSourceObjectVO = new DataSourceObjectVO();
        //关联字段
        DataSourceObjectVO linkDataSourceObjectVO = new DataSourceObjectVO();
        //地址类型
        DataSourceObjectVO addressDataSourceObjectVO = new DataSourceObjectVO();
        //漏斗维度类型
        DataSourceObjectVO funnelDataSourceObjectVO = new DataSourceObjectVO();
        Long formId = slaveSourcePojo.getFormId();
        Integer businessType = slaveSourcePojo.getBusinessType();
        Integer distributorMark = slaveSourcePojo.getDistributorMark();
        showDataSourceObjectVO.setFormId(formId);
        groupDataSourceObjectVO.setFormId(formId);
        selectDataSourceObjectVO.setFormId(formId);
        dashboardSourceObjectVO.setFormId(formId);
        summaryDataSourceObjectVO.setFormId(formId);
        querySummaryDataSourceObjectVo.setFormId(formId);
        belongDataSourceObjectVO.setFormId(formId);
        timeDataSourceObjectVO.setFormId(formId);
        linkDataSourceObjectVO.setFormId(formId);
        addressDataSourceObjectVO.setFormId(formId);
        funnelDataSourceObjectVO.setFormId(formId);
        String formName = "";
        List<String> linkedSourceNames = slaveSourcePojo.getLinkedSourceName();
        List<FieldAttrEntity> showExplainList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<FieldAttrEntity> groupExplainList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<FieldAttrEntity> selectExplainList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<FieldAttrEntity> linkExplainList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        BIProductEnum bIProductEnum = BIProductEnum.getByCode(businessType);
        BIProductReformEnum biProductReformEnum = BIProductReformEnum.getEnumByProductBusinessType(businessType);
        PaasFormRefEntity paasFormRefEntity = new PaasFormRefEntity();
        PaasFormEntityExt mainPaasForm = new PaasFormEntityExt();
        //关联数据的字段 若存在则无需获取字段解释
        if(fieldAttrEntities != null && fieldAttrEntities.size() > 0){
            formName = slaveSourcePojo.getName();
            for (FieldAttrEntity fieldAttrEntity : fieldAttrEntities) {
                fieldAttrEntity.setFormId(formId);
            }
            selectExplainList = fieldAttrEntities;
            showExplainList = new ArrayList<>((ArrayList) CloneUtil.deepClone(selectExplainList));
            groupExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
            linkExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
        }else {
            if (Objects.nonNull(biProductReformEnum)) {
                PaasFormExplainEntity paasFormExplainEntity = new PaasFormExplainEntity();
                // 查看表单主表信息
                PaasFormEntityExt paasFormEntityExt = paasFormModel.getByKey(formId, corpid);
                if (paasFormEntityExt == null) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                paasFormRefEntity = paasFormRefModel.getMainFormIdByFormId(formId, corpid);
                String proudctAttr = BIProductReformEnum.getProductAttr(businessType, paasFormRefEntity.getType());
                mainPaasForm = paasFormModel.getByKey(paasFormRefEntity.getMainFormId(), corpid);
                paasFormExplainEntity = paasFormExplainModel.getByFormId(paasFormRefEntity.getMainFormId(), corpid);
                if (paasFormExplainEntity == null) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
                }
                List<FieldAttrEntity> explainList = JSONArray.parseArray(paasFormExplainEntity.getExplains(), FieldAttrEntity.class);
                Map<String, Object> explainMap = explainList.stream().collect(Collectors.toMap(FieldAttrEntity::getAttr, fieldAttrEntity -> fieldAttrEntity));
                FieldAttrEntity productFieldAttrEnity = (FieldAttrEntity) explainMap.get(proudctAttr);
                SubFormPoJo subForm = productFieldAttrEnity.getSubForm();
                //因为产品名称会在下面给过滤掉，所以这边需要给产品名称表单解释重新赋值一下，以及增加一个产品编号的表单解释
                List<FieldAttrEntity> subFormList = new ArrayList<>();
                handleSubProductFieldList(subFormList, subForm, formId, paasFormRefEntity);

                selectExplainList = subFormList;
                showExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
                groupExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
                linkExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
                if (!BIProductReformEnum.getMultipleProductCodeList().contains(businessType)) {
                    formName = String.format(I18nMessageUtil.getMessage(RelatedProductConstant.PRODUCT_LINK_NAME), mainPaasForm.getName());
                }else {
                    formName = String.format(I18nMessageUtil.getMessage(RelatedProductConstant.PRODUCT_LINK_NAME_SEN), mainPaasForm.getName(), productFieldAttrEnity.getAttrName());
                }
            } else if (Objects.equals(XbbRefTypeEnum.CONTRACT_PERFORMANCE.getCode(), businessType)) {
                //业绩分配
                for (ContractPerformanceEnum contractPerformanceEnum : ContractPerformanceEnum.values()) {
                    FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
                    BeanUtil.copyProperties(contractPerformanceEnum, fieldAttrEntity);
                    showExplainList.add(fieldAttrEntity);
                }
                formName = XbbRefTypeEnum.CONTRACT_PERFORMANCE.getName();
                for (FieldAttrEntity fieldAttrEntity : showExplainList) {
                    fieldAttrEntity.setFormId(formId);
                }
                selectExplainList.addAll((ArrayList)CloneUtil.deepClone(showExplainList));
                groupExplainList.addAll((ArrayList)CloneUtil.deepClone(showExplainList));
            } else {
                FormExplainPojo formExplainPojo = formExplainHelp.getFormAndExplain(corpid, businessType, formId);
                formName = formExplainPojo.getFormName();
                distributorMark = formExplainPojo.getDistributorMark();
                selectExplainList = formExplainPojo.getExplainList();
                showExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
                groupExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
                linkExplainList = new ArrayList<>((ArrayList)CloneUtil.deepClone(selectExplainList));
            }
        }
        Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMapByList(showExplainList, null);
        filterSelectList(chartType, selectExplainList, bIProductEnum);
        Set<String> selectAttrSet = new HashSet<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for (FieldAttrEntity fieldAttrEntity : selectExplainList) {
            selectAttrSet.add(fieldAttrEntity.getAttr());
            // 设置逻辑下拉字段的选项
            List<ItemPoJo> itemPoJos = proFormHelp.getComboItems(fieldAttrEntity, businessType);
            fieldAttrEntity.setItems(itemPoJos);
        }
        //之后distributorMark有值的话可以用
        boolean distributorFlag = Objects.equals(distributorMark, DistributorMarkEnum.DISTRIBUTOR.getCode());
        showExplainList.removeIf(explain ->
                showExplainFliter(chartType, businessType, distributorFlag, explain)
        );
        // 自定义pk把一些不展示字段过滤掉
        if (Objects.equals(chartType, ChartTypeEnum.PK_CUSTOM.getCode())) {
            showExplainList.removeIf(explain ->
                    (Objects.equals(explain.getFieldType(), FieldTypeEnum.REMIND.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.SUB_FORM.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.CONTACT_NUMBER.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.COMBO_LINK_BUSINESS.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_QUERY.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_DATA.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_DATA_MULTI.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.RICH_TEXT.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_BUSINESS_SINGLE.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_BUSINESS_MULTI.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_FORM.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_BUSINESS_COMBO.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_FORM_BUTTON.getType())
                            || !ShowTypeEnum.listShow(explain.getShowType())
                    )
            );
        }
        //包含在筛选条件内的把ScreenType置为SCREEN_SEARCH
        for (FieldAttrEntity fieldAttrEntity : showExplainList) {
            if(selectAttrSet.contains(fieldAttrEntity.getAttr())){
                fieldAttrEntity.setScreenType(ScreenTypeEnum.SCREEN_SEARCH.getType());
            }
            if (XbbRefTypeEnum.PRODUCT.getCode() == businessType.intValue() && ProductEnum.CATEGORY_ID.getAttr().equals(fieldAttrEntity.getAttr())) {
                fieldAttrEntity.setAttrType("text");
            }
        }
        //子表单和数组格式不允许分组以及关联
        filterGroupList(chartType, groupExplainList, businessType);
        //TODO 暂时先把关联隐藏放出来
        linkExplainList.removeIf(explain ->
                ((explain.getScreenType() != null && explain.getScreenType() < ScreenTypeEnum.SCREEN_GROUP.getType())
                        || linkFilterCombo(explain)
                        || FieldTypeEnum.linkAbleFilter(explain.getFieldType())
                        || Objects.equals(explain.getFieldType(), FieldTypeEnum.RICH_TEXT.getType())
                        || Objects.equals(explain.getFieldType(), FieldTypeEnum.LINK_DATA_MULTI.getType())
                        || Objects.equals(explain.getIsOpen(), 0)
                        || ((businessType.intValue() == XbbRefTypeEnum.PRODUCT.getCode()) && Objects.equals(explain.getFieldType(),FieldTypeEnum.CATEGORY_ID.getType())))
                        && !(((Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode() , businessType) || Objects.equals(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), businessType))
                        && (Objects.equals(chartType,ChartTypeEnum.DATA_QUERY_TABLE.getCode()) || Objects.equals(chartType,ChartTypeEnum.DATA_STATISTICS_TABLE.getCode()))
                        && Objects.equals(explain.getAttr(), CommunicateBaseEnum.MEMO.getAttr())))
        );
        setName(showDataSourceObjectVO, selectDataSourceObjectVO, groupDataSourceObjectVO, summaryDataSourceObjectVO, dashboardSourceObjectVO, querySummaryDataSourceObjectVo, belongDataSourceObjectVO, timeDataSourceObjectVO, linkDataSourceObjectVO, addressDataSourceObjectVO, funnelDataSourceObjectVO, formName);

        List<Integer> noSearchIdList = FieldTypeEnum.esaliasTypeList().getNoSearchIdList();
        List<Integer> numIdList = FieldTypeEnum.esaliasTypeList().getNumIdList();
        List<Integer> belongIdList = FieldTypeEnum.esaliasTypeList().getBelongIdList();
        List<Integer> timeIdList = FieldTypeEnum.esaliasTypeList().getTimeIdList();
        List<Integer> addressIdList = FieldTypeEnum.esaliasTypeList().getAddressIdList();
        List<Integer> funnelIdList = FieldTypeEnum.esaliasTypeList().getFunnelIdList();

        Integer saasMark = slaveSourcePojo.getSaasMark();
        Long appId = slaveSourcePojo.getAppId();
        setDataSourceObjectVO(selectExplainList, selectDataSourceObjectVO, saasMark, businessType, appId, corpid, formId, explainMap, ChartAttrTypeEnum.SELECT.getIndex(), chartType);
        setDataSourceObjectVO(groupExplainList, groupDataSourceObjectVO, saasMark, businessType, appId, corpid, formId, explainMap, ChartAttrTypeEnum.GROUP.getIndex(), chartType);
        FieldAttrEntity  dataFieldAttrEntity = new FieldAttrEntity();
        dataFieldAttrEntity.setBusinessType(businessType);
        FieldAttrEntity subProductFieldAttrEntity = null;
        if(BIProductReformEnum.getProductSubBusList().contains(businessType)){
            subProductFieldAttrEntity = new FieldAttrEntity();
            subProductFieldAttrEntity.setBusinessType(businessType);
            BIProductReformEnum biProductReformEnumSen = BIProductReformEnum.getEnumByProductBusinessType(businessType);
            XbbRefTypeEnum mainProductXbbRefTypeEnum = XbbRefTypeEnum.getByCode(XbbRefTypeEnum.PRODUCT.getCode());
            subProductFieldAttrEntity.setAttr(biProductReformEnumSen.getVirtualLinkProductAttr());
            subProductFieldAttrEntity.setFieldType(FieldTypeEnum.LINK_BUSINESS_SINGLE.getType());
            subProductFieldAttrEntity.setAttrName(mainProductXbbRefTypeEnum.getName() + RelatedProductConstant.ATTR_NAME_JOIN);

            XbbRefTypeEnum mainXbbRefTypeEnum = XbbRefTypeEnum.getByCode(paasFormRefEntity.getMainBusinessType());
            String attrName = "";
            if (Objects.nonNull(mainPaasForm) && Objects.equals(mainPaasForm.getDistributorMark(), DistributorMarkEnum.DISTRIBUTOR.getCode())) {
                //兼容经销商的场景
                attrName = mainPaasForm.getName() + RelatedProductConstant.ATTR_NAME_JOIN;
            }else {
                attrName = mainXbbRefTypeEnum.getName() + RelatedProductConstant.ATTR_NAME_JOIN;
            }
            dataFieldAttrEntity.setAttr(biProductReformEnumSen.getVirtualLinkMainBusinessAttr());
            dataFieldAttrEntity.setFieldType(FieldTypeEnum.LINK_BUSINESS_SINGLE.getType());
            dataFieldAttrEntity.setAttrName(attrName);
        }else if(Objects.equals(XbbRefTypeEnum.CONTRACT_PERFORMANCE.getCode(), businessType)){
            dataFieldAttrEntity.setAttr(ContractPerformanceSubFormEnum.CONTRACT_ID.getDataAttr());
            dataFieldAttrEntity.setFieldType(FieldTypeEnum.LINK_BUSINESS_SINGLE.getType() );
            dataFieldAttrEntity.setAttrName("关联ID");
        }else if(Objects.equals(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), businessType)){
            dataFieldAttrEntity.setAttr("dataId");
            dataFieldAttrEntity.setFieldType(FieldTypeEnum.DATAID.getType());
            dataFieldAttrEntity.setAttrName("ID");
            linkExplainList.add(dataFieldAttrEntity);
            //回款单加上关联合同
            for (FieldAttrEntity fieldAttrEntity : showExplainList) {
                if(Objects.equals(PaymentSheetEnum.CONTRACT.getAttr(),fieldAttrEntity.getAttr())){
                    dataFieldAttrEntity = fieldAttrEntity;
                    break;
                }
            }
        } else {
            dataFieldAttrEntity.setAttr("dataId");
            dataFieldAttrEntity.setFieldType(FieldTypeEnum.DATAID.getType());
            dataFieldAttrEntity.setAttrName("ID");
        }
        linkExplainList.add(dataFieldAttrEntity);
        if (Objects.nonNull(subProductFieldAttrEntity)) {
            linkExplainList.add(subProductFieldAttrEntity);
        }
        setDataSourceObjectVO(linkExplainList, linkDataSourceObjectVO, saasMark, businessType, appId, corpid, formId, explainMap, ChartAttrTypeEnum.LINK.getIndex(), chartType);
        List<String> linkedNames = new ArrayList<>();
        //开启ck，且传入的图表类型支持钻取
        boolean drillFlag = ChartTypeEnum.supportDrillSet(chartLimitService.getCkFlag(), chartType);
        if(CollectionsUtil.isNotEmpty(showExplainList)){
            Iterator<FieldAttrEntity> explainIt = showExplainList.iterator();
            while (explainIt.hasNext()){
                FieldAttrEntity fieldAttrEntity = explainIt.next();
                // 字段回收站处理
                if (Objects.equals(fieldAttrEntity.getIsOpen(), 2)) {
                    continue;
                }
                if(Objects.equals(fieldAttrEntity.getFieldType(),FieldTypeEnum.TEMPLATE_FIELD.getType())){
                    // 不需要被设置选中
                    continue;
                }
                fieldAttrEntity.setBusinessType(businessType);
                FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldAttrEntity.getFieldType());
                classifyField(dataSourceAttrVO, corpid, single, chartType, showDataSourceObjectVO, summaryDataSourceObjectVO, querySummaryDataSourceObjectVo, belongDataSourceObjectVO, timeDataSourceObjectVO, addressDataSourceObjectVO, funnelDataSourceObjectVO, formId, businessType, linkedSourceNames, explainMap, noSearchIdList, numIdList, belongIdList, timeIdList, addressIdList, funnelIdList, saasMark, appId, linkedNames, fieldAttrEntity, fieldTypeEnum);
            }
            setDashBoardVO(corpid, saasMark, businessType, appId, formId, chartType, showDataSourceObjectVO, groupDataSourceObjectVO, dashboardSourceObjectVO, numIdList, belongIdList, drillFlag);
            setCountField(chartType, summaryDataSourceObjectVO, dashboardSourceObjectVO, formId);
        }
        //添加关联数据中的标题名称(单表内唯一)
        slaveSourcePojo.setLinkedSourceName(linkedNames);
        //兼容处理，防止表单设计的时候没有拖
        List<? super FieldAttrEntity> belongList = belongDataSourceObjectVO.getFieldList();
        // 为空且不是关联产品和业绩分配，或者是经销商档案，默认加创建人
        if((belongList.isEmpty() && !Objects.equals(XbbRefTypeEnum.CONTRACT_PERFORMANCE.getCode(), businessType) && !BIProductReformEnum.getProductSubBusList().contains(businessType))
                || (Objects.equals(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), businessType) && Objects.equals(DistributorMarkEnum.DISTRIBUTOR.getCode(), distributorMark))){
            //设置创建人
            ChartFieldAttrPojo chartFieldAttrPojo = setAttrField(FieldTypeEnum.CREATORID,slaveSourcePojo);
            belongDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
        }
        List<? super FieldAttrEntity> timeList = timeDataSourceObjectVO.getFieldList();
        if(timeList.isEmpty()){
            //设置创建时间
            ChartFieldAttrPojo chartFieldAttrPojo =  setAttrField(FieldTypeEnum.ADDTIME,slaveSourcePojo);
            timeDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
        }

        setDataSourceVO(dataSourceAttrVO, showDataSourceObjectVO, selectDataSourceObjectVO, groupDataSourceObjectVO, summaryDataSourceObjectVO, dashboardSourceObjectVO, querySummaryDataSourceObjectVo, belongDataSourceObjectVO, timeDataSourceObjectVO, linkDataSourceObjectVO, addressDataSourceObjectVO, funnelDataSourceObjectVO, drillFlag);
    }

    /**
     * 设置计数字段
     * @param chartType  图表类型
     * @param summaryDataSourceObjectVO   可汇总字段
     * @param dashboardSourceObjectVO  仪表盘需要的字段
     * @param formId 表单id
     */
    public void setCountField(Integer chartType, DataSourceObjectVO summaryDataSourceObjectVO, DataSourceObjectVO dashboardSourceObjectVO, Long formId) {
        //若表头字段无可选的就过滤掉  计数
        ChartFieldAttrPojo chartFieldAttrPojo =  setAttrField(FieldTypeEnum.COUNT,null);
        chartFieldAttrPojo.setScreenType(ScreenTypeEnum.SCREEN_SHOW.getType());
        JSONArray  statisticsWayArray = new JSONArray();
        getReturnArray(statisticsWayArray,AggTypeEnum.getListByCode(AggTypeEnum.COUNT.getCode()));
        chartFieldAttrPojo.setStatisticsWayArray(statisticsWayArray);
        //单位
        JSONArray  unitWayArray = new JSONArray();
        getReturnArray(unitWayArray,UnitEnum.getListByAlias(UnitEnum.NUMBER.getAlias()));
        chartFieldAttrPojo.setUnitArray(unitWayArray);
        chartFieldAttrPojo.setFormId(formId);
        // ck后新功能限制
        if (chartLimitService.getCkFlag()) {
            chartFieldAttrPojo.setCkShowFlag(1);
        } else {
            chartFieldAttrPojo.setCkShowFlag(0);
        }
        summaryDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
        //TODO 小计有需要加在上面方法里
        if (!Objects.equals(chartType, ChartTypeEnum.DATA_QUERY_TABLE.getCode())) {
            dashboardSourceObjectVO.addFieldList(chartFieldAttrPojo);
        }
    }

    public boolean showExplainFliter(Integer chartType, Integer businessType, boolean distributorFlag, FieldAttrEntity explain) {
        return (explain.getScreenType() != null && explain.getScreenType() < ScreenTypeEnum.SCREEN_SHOW.getType()) || FieldTypeEnum.showAbleFilter(explain.getFieldType())
                || Objects.equals(explain.getIsOpen(), 0)
                || (Objects.equals(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), businessType) && distributorFlag && (Objects.equals(explain.getAttr(), "num_3") || Objects.equals(explain.getAttr(), "num_4")))
                || (Objects.equals(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(), businessType) && Objects.equals(explain.getFieldType(), FieldTypeEnum.CREATORID.getType()))
                || (Objects.equals(businessType, XbbRefTypeEnum.RECEIPT_ORDER.getCode()) && Objects.equals(explain.getFieldType(), FieldTypeEnum.TEXTAREA.getType()))
                || ((Objects.equals(XbbRefTypeEnum.SLA_LOG.getCode(), businessType)) && Objects.equals(explain.getFieldType(), FieldTypeEnum.TEXTAREA.getType()))
                || ((Objects.equals(XbbRefTypeEnum.WORK_ORDER_V2.getCode(), businessType) && Objects.equals(explain.getFieldType(), FieldTypeEnum.CONTACT_NUMBER.getType())))
                || (((Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), businessType) || Objects.equals(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), businessType))
                && !(Objects.equals(chartType, ChartTypeEnum.DATA_QUERY_TABLE.getCode()) || Objects.equals(chartType, ChartTypeEnum.DATA_STATISTICS_TABLE.getCode()))
                && Objects.equals(explain.getAttr(), CommunicateBaseEnum.MEMO.getAttr())));
    }

    public void setDashBoardVO(String corpid, Integer saasMark, Integer businessType, Long appId, Long formId, Integer chartType, DataSourceObjectVO showDataSourceObjectVO, DataSourceObjectVO groupDataSourceObjectVO, DataSourceObjectVO dashboardSourceObjectVO, List<Integer> numIdList, List<Integer> belongIdList, boolean drillFlag) throws XbbException {
        List<? super FieldAttrEntity> groupFieldList = groupDataSourceObjectVO.getFieldList();
        List<? super FieldAttrEntity> dashboardExplainList  = new ArrayList<>((ArrayList)CloneUtil.deepClone(showDataSourceObjectVO.getFieldList()));
        List tempDashboardExplainList = new ArrayList<>();
        //支持分组的字段才能钻取（前端是用dashboardAble渲染）
        List<String> supportDrillAttr = new ArrayList<>();
        for (Object e : groupFieldList) {
            ChartFieldAttrPojo fieldAttrPojo = (ChartFieldAttrPojo) e;
            Integer fieldType = fieldAttrPojo.getFieldType();
            //图表类型支持钻取，字段类型非数字
            if (drillFlag && !numIdList.contains(fieldType)) {
                //支持钻取的图表，该group内的所有字段都可以设置为钻取层级字段：非数值类型字段，且可以作为分类、系列、行分组、列分组的字段才允许创建层级结构
                supportDrillAttr.add(fieldAttrPojo.getAttr());
            }
            if(Objects.equals(fieldType,FieldTypeEnum.TEMPLATE_FIELD.getType())){
                // 不需要被设置选中
                continue;
            }
            //查询表无需再次塞入地址字段
            if (Objects.equals(fieldType, FieldTypeEnum.ADDRESS.getType()) && !Objects.equals(chartType, ChartTypeEnum.DATA_QUERY_TABLE.getCode())) {
                dashboardExplainList.add(fieldAttrPojo);
            }
        }
        Iterator<? super FieldAttrEntity> iterator = dashboardExplainList.iterator();
        while (iterator.hasNext()) {
            ChartFieldAttrPojo fieldAttrPojo = (ChartFieldAttrPojo) iterator.next();
            // 人员字段在筛选时默认展示离职人员
            Integer fieldType = fieldAttrPojo.getFieldType();
            if (belongIdList.contains(fieldType)) {
                fieldAttrPojo.setLeaveMarks(LeaveMarksEnum.IS_SHOW.getCode());
            }
            //图表类型支持钻取，字段类型支持分组
            if (supportDrillAttr.contains(fieldAttrPojo.getAttr())) {
                fieldAttrPojo.setDrill(BasicConstant.ONE);
                if (EsHelper.isDateTimeByFieldType(fieldType)) {
                    //支持钻取的时间类型字段拆分为5个字段
                    List<FieldAttrEntity> dateList = dateParse(fieldAttrPojo, iterator);
                    for(FieldAttrEntity entity :dateList){
                        //数据集调用的时候传空，在字段内获取
                        if(saasMark == null || businessType== null || formId== null){
                            saasMark = entity.getSaasMark();
                            businessType = entity.getBusinessType();
                            formId = entity.getFormId();
                        }
                        ChartFieldAttrPojo datePojo = commonDataSourceAttrEnclosure(entity, businessType, corpid, formId);
                        datePojo.setSaasMark(saasMark);
                        datePojo.setBusinessType(businessType);
                        datePojo.setAppId(appId);
                    }
                    //支持钻取的时间字段，拆分成5个，塞入到底部，且原时间字段会移除
                    tempDashboardExplainList.addAll(dateList);
                }
            }
        }
        dashboardExplainList.addAll(tempDashboardExplainList);
        dashboardSourceObjectVO.setFieldList(dashboardExplainList);
    }

    public void setName(DataSourceObjectVO showDataSourceObjectVO, DataSourceObjectVO selectDataSourceObjectVO, DataSourceObjectVO groupDataSourceObjectVO, DataSourceObjectVO summaryDataSourceObjectVO, DataSourceObjectVO dashboardSourceObjectVO, DataSourceObjectVO querySummaryDataSourceObjectVo, DataSourceObjectVO belongDataSourceObjectVO, DataSourceObjectVO timeDataSourceObjectVO, DataSourceObjectVO linkDataSourceObjectVO, DataSourceObjectVO addressDataSourceObjectVO, DataSourceObjectVO funnelDataSourceObjectVO, String formName) {
        showDataSourceObjectVO.setName(formName);
        selectDataSourceObjectVO.setName(formName);
        dashboardSourceObjectVO.setName(formName);
        summaryDataSourceObjectVO.setName(formName);
        querySummaryDataSourceObjectVo.setName(formName);
        belongDataSourceObjectVO.setName(formName);
        timeDataSourceObjectVO.setName(formName);
        groupDataSourceObjectVO.setName(formName);
        linkDataSourceObjectVO.setName(formName);
        addressDataSourceObjectVO.setName(formName);
        funnelDataSourceObjectVO.setName(formName);
    }

    /**
     * 移除不可筛选字段
     * @param chartType
     * @param selectExplainList
     * @param bIProductEnum
     */
    public void filterSelectList(Integer chartType, List<FieldAttrEntity> selectExplainList, BIProductEnum bIProductEnum) {
        //二次筛选-枚举类screenType判定
        selectExplainList.removeIf(explain ->
                (explain.getScreenType()!=null && explain.getScreenType() < ScreenTypeEnum.SCREEN_SEARCH.getType()) || FieldTypeEnum.selectAbleFilter(explain.getFieldType())
                        || Objects.equals(explain.getIsOpen(), 0)
                        || (bIProductEnum != null && Objects.equals(explain.getAttr(), ContractProductBIEnum.UNIT.getAttr()))
        );
        // 自定义pk把人员和部门相关的过滤掉，避免和范围筛选冲突
        if (Objects.equals(chartType, ChartTypeEnum.PK_CUSTOM.getCode())) {
            selectExplainList.removeIf(explain ->
                    Objects.equals(explain.getFieldType(), FieldTypeEnum.SELECT_DEPARTMENT.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.USER.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.USER_GROUP.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.DEPT.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.DEPT_GROUP.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.CREATORID.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.DEPARTMENTID.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.OWNERID.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.COUSERID.getType())
                            || Objects.equals(explain.getFieldType(), FieldTypeEnum.COPY_USER.getType())
            );
        }
    }

    /**
     * 移除不可分组的字段
     * @param chartType
     * @param groupExplainList
     * @param businessType
     */
    public void filterGroupList(Integer chartType, List<FieldAttrEntity> groupExplainList,Integer businessType) {
        groupExplainList.removeIf(explain -> {
            Integer businessType1 = businessType;
            if(businessType == null){
                businessType1 = explain.getBusinessType();
            }
            return ((explain.getScreenType() != null && explain.getScreenType() < ScreenTypeEnum.SCREEN_GROUP.getType())
                    || FieldTypeEnum.groupAbleFilter(explain.getFieldType()))
                    || Objects.equals(explain.getIsOpen(), 0)
                    || (((Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), businessType1) || Objects.equals(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), businessType1))
                    && (Objects.equals(chartType, ChartTypeEnum.DATA_QUERY_TABLE.getCode()) || Objects.equals(chartType, ChartTypeEnum.DATA_STATISTICS_TABLE.getCode()))
                    && Objects.equals(explain.getAttr(), CommunicateBaseEnum.MEMO.getAttr())));
        }
        );
    }

    /**
     * 设置返回值和国际化
     * @param dataSourceAttrVO
     * @param showDataSourceObjectVO
     * @param selectDataSourceObjectVO
     * @param groupDataSourceObjectVO
     * @param summaryDataSourceObjectVO
     * @param dashboardSourceObjectVO
     * @param querySummaryDataSourceObjectVo
     * @param belongDataSourceObjectVO
     * @param timeDataSourceObjectVO
     * @param linkDataSourceObjectVO
     * @param addressDataSourceObjectVO
     * @param funnelDataSourceObjectVO
     * @param drillFlag
     */
    public void setDataSourceVO(DataSourceAttrVO dataSourceAttrVO, DataSourceObjectVO showDataSourceObjectVO, DataSourceObjectVO selectDataSourceObjectVO, DataSourceObjectVO groupDataSourceObjectVO, DataSourceObjectVO summaryDataSourceObjectVO, DataSourceObjectVO dashboardSourceObjectVO, DataSourceObjectVO querySummaryDataSourceObjectVo, DataSourceObjectVO belongDataSourceObjectVO, DataSourceObjectVO timeDataSourceObjectVO, DataSourceObjectVO linkDataSourceObjectVO, DataSourceObjectVO addressDataSourceObjectVO, DataSourceObjectVO funnelDataSourceObjectVO, boolean drillFlag) {
        //若各项数据为null
        if(CollectionsUtil.isNotEmpty(showDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(showDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addShowAble(showDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(groupDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(groupDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addGroupAble(groupDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(selectDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(selectDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addSelectAble(selectDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(summaryDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(summaryDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addSummaryAble(summaryDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(querySummaryDataSourceObjectVo.getFieldList())) {
            changeNameWithI18n(querySummaryDataSourceObjectVo.getFieldList());
            dataSourceAttrVO.addStatisticSummaryAble(querySummaryDataSourceObjectVo);
        }
        if(CollectionsUtil.isNotEmpty(belongDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(belongDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addBelongAble(belongDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(timeDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(timeDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addTimeAble(timeDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(dashboardSourceObjectVO.getFieldList())) {
            changeNameWithI18n(dashboardSourceObjectVO.getFieldList());
            dataSourceAttrVO.addDashboardAble(dashboardSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(addressDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(addressDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addAddressAble(addressDataSourceObjectVO);
        }
        if(CollectionsUtil.isNotEmpty(funnelDataSourceObjectVO.getFieldList())) {
            changeNameWithI18n(funnelDataSourceObjectVO.getFieldList());
            dataSourceAttrVO.addFunnelAble(funnelDataSourceObjectVO);
        }
        dataSourceAttrVO.setDrillFlag(drillFlag);
        if (drillFlag) {
            SpecialFieldPojo specialFieldPojo = new SpecialFieldPojo(FieldTypeEnum.depList(), FieldTypeEnum.categoryList());
            dataSourceAttrVO.setSpecialField(specialFieldPojo);
        }
        //link  没有的话也会存在结构的意义
        changeNameWithI18n(linkDataSourceObjectVO.getFieldList());
        dataSourceAttrVO.addLinkAble(linkDataSourceObjectVO);
    }

    public void classifyField(DataSourceAttrVO dataSourceAttrVO, String corpid, Integer single, Integer chartType, DataSourceObjectVO showDataSourceObjectVO, DataSourceObjectVO summaryDataSourceObjectVO, DataSourceObjectVO querySummaryDataSourceObjectVo, DataSourceObjectVO belongDataSourceObjectVO, DataSourceObjectVO timeDataSourceObjectVO, DataSourceObjectVO addressDataSourceObjectVO, DataSourceObjectVO funnelDataSourceObjectVO, Long formId, Integer businessType, List<String> linkedSourceNames, Map<String, FieldAttrEntity> explainMap, List<Integer> noSearchIdList, List<Integer> numIdList, List<Integer> belongIdList, List<Integer> timeIdList, List<Integer> addressIdList, List<Integer> funnelIdList, Integer saasMark, Long appId, List<String> linkedNames, FieldAttrEntity fieldAttrEntity, FieldTypeEnum fieldTypeEnum) throws XbbException {
        classifyField(dataSourceAttrVO,  corpid,  single,  chartType,  showDataSourceObjectVO,  summaryDataSourceObjectVO,  querySummaryDataSourceObjectVo,  belongDataSourceObjectVO,  timeDataSourceObjectVO,  addressDataSourceObjectVO,  funnelDataSourceObjectVO,  formId,  businessType,linkedSourceNames, explainMap, noSearchIdList,  numIdList,  belongIdList,  timeIdList,  addressIdList,  funnelIdList,  saasMark,  appId, linkedNames,  fieldAttrEntity,  fieldTypeEnum,false);
    }
    
    /**
     * 字段归类
     * @param dataSourceAttrVO
     * @param corpid
     * @param single
     * @param chartType
     * @param showDataSourceObjectVO
     * @param summaryDataSourceObjectVO
     * @param querySummaryDataSourceObjectVo
     * @param belongDataSourceObjectVO
     * @param timeDataSourceObjectVO
     * @param addressDataSourceObjectVO
     * @param funnelDataSourceObjectVO
     * @param formId
     * @param businessType
     * @param linkedSourceNames
     * @param explainMap
     * @param noSearchIdList
     * @param numIdList
     * @param belongIdList
     * @param timeIdList
     * @param addressIdList
     * @param funnelIdList
     * @param saasMark
     * @param appId
     * @param linkedNames
     * @param fieldAttrEntity
     * @param fieldTypeEnum
     * @throws XbbException
     */
    public void classifyField(DataSourceAttrVO dataSourceAttrVO, String corpid, Integer single, Integer chartType, DataSourceObjectVO showDataSourceObjectVO, DataSourceObjectVO summaryDataSourceObjectVO, DataSourceObjectVO querySummaryDataSourceObjectVo, DataSourceObjectVO belongDataSourceObjectVO, DataSourceObjectVO timeDataSourceObjectVO, DataSourceObjectVO addressDataSourceObjectVO, DataSourceObjectVO funnelDataSourceObjectVO, Long formId, Integer businessType, List<String> linkedSourceNames, Map<String, FieldAttrEntity> explainMap, List<Integer> noSearchIdList, List<Integer> numIdList, List<Integer> belongIdList, List<Integer> timeIdList, List<Integer> addressIdList, List<Integer> funnelIdList, Integer saasMark, Long appId, List<String> linkedNames, FieldAttrEntity fieldAttrEntity, FieldTypeEnum fieldTypeEnum,boolean dataSetChartFlag) throws XbbException {
        ChartFieldAttrPojo chartFieldAttrPojo = new ChartFieldAttrPojo();
        chartFieldAttrPojo.setAppId(appId);
        chartFieldAttrPojo.setSaasMark(saasMark);
        if(FieldTypeEnum.LINK_DATA.equals(fieldTypeEnum) || FieldTypeEnum.LINK_DATA_MULTI.equals(fieldTypeEnum)){
            if(Objects.equals(1, single) && !Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), businessType) && (ChartTypeEnum.TARGET_CHART.getCode() != chartType && ChartTypeEnum.SECOND_TARGET_CHART.getCode() != chartType)){
                linkedDataAttrHandle(fieldAttrEntity, corpid, linkedNames, dataSourceAttrVO, linkedSourceNames, chartType);
            }
            return;
        }else if(FieldTypeEnum.ADDRESS.equals(fieldTypeEnum)){
//                    fieldAttrEntityList = addressParse(fieldAttrEntity,explainIt);
//                    for(FieldAttrEntity entity :fieldAttrEntityList){
//                        showDataSourceObjectVO.addFieldList(entity);
//                    }
//                    continue;
            if(dataSetChartFlag){
                BeanUtil.copyProperties(fieldAttrEntity,chartFieldAttrPojo);
            }else {
                chartFieldAttrPojo = commonDataSourceAttrEnclosure(fieldAttrEntity, businessType, corpid, formId);
            }
        } else if (FieldTypeEnum.isSubFormType(fieldAttrEntity.getFieldType())){
            // 子表单处理
            subFormAttrHandle(fieldAttrEntity, showDataSourceObjectVO, numIdList, querySummaryDataSourceObjectVo, businessType, saasMark, appId);
            return;
        } else {
            if (FieldTypeEnum.LINK_BUSINESS_SINGLE.equals(fieldTypeEnum) || FieldTypeEnum.LINK_BUSINESS_MULTI.equals(fieldTypeEnum) || FieldTypeEnum.BIRTHDAY.equals(fieldTypeEnum)) {
                BeanUtil.copyProperties(fieldAttrEntity, chartFieldAttrPojo);
                FieldAttrEntity linkedAttr = explainMap.get(chartFieldAttrPojo.getLinkedText());
                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(linkedAttr));
                if (Objects.nonNull(jsonObject)){
                    jsonObject.put(StringConstant.FORM_ID, formId);
                    chartFieldAttrPojo.setLinkedAttr(jsonObject);
                }
            } else {
                if(dataSetChartFlag){
                    BeanUtil.copyProperties(fieldAttrEntity,chartFieldAttrPojo);
                }else {
                    chartFieldAttrPojo = commonDataSourceAttrEnclosure(fieldAttrEntity, businessType, corpid, formId);
                }
            }
        }
        Integer fieldType = chartFieldAttrPojo.getFieldType();
        if (!noSearchIdList.contains(fieldType)) {
            if (numIdList.contains(fieldType) || Objects.equals(fieldAttrEntity.getAmountFlag(), AmountFlagEnum.YES.getType()) ) {
                //统计方式
                JSONArray statisticsWayArray = new JSONArray();
                getReturnArray(statisticsWayArray, AggTypeEnum.list());
                chartFieldAttrPojo.setStatisticsWayArray(statisticsWayArray);
                //单位
                JSONArray  unitWayArray = new JSONArray();
                getReturnArray(unitWayArray, UnitEnum.list());
                chartFieldAttrPojo.setUnitArray(unitWayArray);
                //chartFieldAttrPojo.setAttrType(fieldTypeEnum.getAlias());
                if (Objects.isNull(chartFieldAttrPojo.getAttrType())){
                    chartFieldAttrPojo.setAttrType(fieldTypeEnum.getAlias());
                }
                // ck后新功能限制
                if (chartLimitService.getCkFlag()) {
                    chartFieldAttrPojo.setCkShowFlag(1);
                } else {
                    chartFieldAttrPojo.setCkShowFlag(0);
                }
                querySummaryDataSourceObjectVo.addFieldList(chartFieldAttrPojo);
                summaryDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
            }else if (belongIdList.contains(fieldType)){
                // 自定义pk，归属人过滤掉可以添加多个人员的字段，计算分配时会有问题，江哥说的
                boolean customPkFlag = Objects.equals(chartType, ChartTypeEnum.PK_CUSTOM.getCode())
                        && (Objects.equals(FieldTypeEnum.OWNERID.getType(), fieldType)
                        || Objects.equals(FieldTypeEnum.COUSERID.getType(), fieldType)
                        || Objects.equals(FieldTypeEnum.USER_GROUP.getType(), fieldType)
                );
                if (!customPkFlag) {
                    belongDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
                }
            }else if(timeIdList.contains(fieldType)){
                timeDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
            }else if(addressIdList.contains(fieldType)){
                addressDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
            }else if(funnelIdList.contains(fieldType)){
                funnelDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
            }
            //查询下拉选需要传saaaMark
            chartFieldAttrPojo.setSaasMark(saasMark);
            showDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
        }
    }

    /**
     * 地址分成4个 来显示
     * @param fieldAttrEntity
     * @param it
     */
    private List<FieldAttrEntity> addressParse(FieldAttrEntity fieldAttrEntity, Iterator<FieldAttrEntity> it) {
        List<FieldAttrEntity> addressList = new ArrayList<>();
        for (AddressEnum addressEnum : AddressEnum.getAllEnum()) {
            if (addressEnum == AddressEnum.ADDRESS) {
                continue;
            }
            FieldAttrEntity entity = new FieldAttrEntity();
            BeanUtil.copyProperties(fieldAttrEntity, entity);
            entity.setAttrName(fieldAttrEntity.getAttrName() + "." + addressEnum.getName());
            entity.setAttr(fieldAttrEntity.getAttr() + "." + addressEnum.getAlias());
            entity.setDrill(BasicConstant.ONE);
            addressList.add(entity);
        }
        it.remove();
        return addressList;
    }
    /**
     * 支持钻取的时间字段分成5个 来显示
     * @param fieldAttrEntity
     * @param it
     * @return java.util.List<com.xbongbong.paas.pojo.FieldAttrEntity>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    private List<FieldAttrEntity> dateParse(FieldAttrEntity fieldAttrEntity, Iterator<? super FieldAttrEntity> it) {
        List<FieldAttrEntity> dateList = new ArrayList<>();
        for (IntervalTypeEnum cache : IntervalTypeEnum.drillParseList()) {
            FieldAttrEntity entity = new FieldAttrEntity();
            BeanUtil.copyProperties(fieldAttrEntity, entity);
            entity.setDateGroupType(cache.getFormat());
            entity.setDrill(BasicConstant.ONE);
            dateList.add(entity);
        }
        it.remove();
        return dateList;
    }

    /**
     * 获取标准格式的array
     * @param jsonArray
     */
    private void getReturnArray(JSONArray jsonArray,List<AggsTypeClass> list ) {
        for (AggsTypeClass aggsTypeClass : list) {
            WidgetSelectPojo widgetSelectPojo = new WidgetSelectPojo();
            widgetSelectPojo.setKey(aggsTypeClass.getAlias());
            widgetSelectPojo.setValue(aggsTypeClass.getName());
            jsonArray.add(widgetSelectPojo);
        }
    }
    
    /**
     * 子表单字段处理
     * @param fieldAttrEntity 字段属性
     * @param dataSourceObjectVO 字段返回对象
     * @param numIdList 汇总字段type类型集合
     * @param querySummaryDataSourceObjectVo 统计表汇总字段
     * @author zhouwq
     * @date 2019/6/27 14:27
     */
    public void subFormAttrHandle(FieldAttrEntity fieldAttrEntity, DataSourceObjectVO dataSourceObjectVO, List<Integer> numIdList, DataSourceObjectVO querySummaryDataSourceObjectVo, Integer businessType, Integer saasMark, Long appId){
        SubFormPoJo subFormPoJo = fieldAttrEntity.getSubForm();
        List<FieldAttrEntity> subFormAttrs = JSONArray.parseArray(JSON.toJSONString(subFormPoJo.getItems()),FieldAttrEntity.class);
        subFormAttrs.forEach(entity -> {
            //过滤子表单内地址字段
            if(Objects.equals(entity.getFieldType(), FieldTypeEnum.ADDRESS.getType()) || Objects.equals(entity.getFieldType(), FieldTypeEnum.LINK_DATA.getType())
                    || Objects.equals(entity.getFieldType(), FieldTypeEnum.RICH_TEXT.getType())
                    || Objects.equals(entity.getFieldType(), FieldTypeEnum.LINK_DATA_MULTI.getType())
                    || Objects.equals(entity.getFieldType(), FieldTypeEnum.IMAGE.getType()) || Objects.equals(entity.getFieldType(), FieldTypeEnum.UPLOAD.getType()) || Objects.equals(entity.getFieldType(), FieldTypeEnum.LOCATION.getType())
                    || Objects.equals(entity.getIsOpen(), 2)) {
                return;
            }
            ChartFieldAttrPojo chartFieldAttrPojo = new ChartFieldAttrPojo();
            BeanUtil.copyProperties(entity, chartFieldAttrPojo);
            chartFieldAttrPojo.setAttrName(fieldAttrEntity.getAttrName() + SymbolConstant.POINT_ENGLISH + chartFieldAttrPojo.getAttrName());
            chartFieldAttrPojo.setAttr(fieldAttrEntity.getAttr() + SymbolConstant.POINT_ENGLISH  + chartFieldAttrPojo.getAttr());
            chartFieldAttrPojo.setParentSubFormAttr(fieldAttrEntity);
            chartFieldAttrPojo.setAppId(appId);
            chartFieldAttrPojo.setSaasMark(saasMark);
            chartFieldAttrPojo.setBusinessType(businessType);
            chartFieldAttrPojo.setFormId(fieldAttrEntity.getFormId());
            if(Objects.equals(businessType,XbbRefTypeEnum.SUPPLIER_CONTACT.getCode()) && StringUtil.isEmpty(fieldAttrEntity.getParentAttr())){
                chartFieldAttrPojo.setParentAttr(fieldAttrEntity.getAttr());
            }
            // 汇总字段添加
            if(numIdList != null && numIdList.size() > 0) {
                if (numIdList.contains(chartFieldAttrPojo.getFieldType())) {
                    //统计方式
                    JSONArray statisticsWayArray = new JSONArray();
                    getReturnArray(statisticsWayArray, AggTypeEnum.list());
                    chartFieldAttrPojo.setStatisticsWayArray(statisticsWayArray);
                    //单位
                    JSONArray unitWayArray = new JSONArray();
                    getReturnArray(unitWayArray, UnitEnum.list());
                    chartFieldAttrPojo.setUnitArray(unitWayArray);
                    querySummaryDataSourceObjectVo.addFieldList(chartFieldAttrPojo);
//                    summaryDataSourceObjectVO.addFieldList(chartFieldAttrPojo);
                }
            }
            if(!FieldTypeEnum.baseFilter(chartFieldAttrPojo.getFieldType())){
                dataSourceObjectVO.addFieldList(chartFieldAttrPojo);
            }
        });
    }

    public void setDataSourceObjectVO(List<FieldAttrEntity> explainList, DataSourceObjectVO dataSourceObjectVO
            , Integer saasMark, Integer businessType, Long appId, String corpid, Long formId, Map<String, FieldAttrEntity> explainMap, int chartAttrType, Integer chartType) throws XbbException {
        setDataSourceObjectVO(explainList, dataSourceObjectVO, saasMark, businessType, appId, corpid, formId, explainMap, chartAttrType, chartType,false);
    }
    /**
     * 字段返回对象处理
     * @param explainList 字段解释
     * @param dataSourceObjectVO 字段返回对象
     * @param saasMark 系统标志
     * @param businessType 业务模板对应code
     * @param appId 应用ID
     * @param explainMap 字段对应关系
     * @param   dataSetChartFlag   数据集图表中心的调用              
     * @author zhouwq
     * @date 2019/7/1 15:07
     */
    public void setDataSourceObjectVO(List<FieldAttrEntity> explainList, DataSourceObjectVO dataSourceObjectVO
            , Integer saasMark, Integer businessType, Long appId, String corpid, Long formId, Map<String, FieldAttrEntity> explainMap, int chartAttrType, Integer chartType,boolean dataSetChartFlag) throws XbbException {
        if(CollectionsUtil.isNotEmpty(explainList)){
            Iterator<FieldAttrEntity> it =explainList.iterator();
            List<Integer> abnormalStatusList = DataSetFieldStatusEnum.abnormalStatusList();
            while (it.hasNext()){
                FieldAttrEntity fieldAttrEntity = it.next();
                //数据集调用的时候传空，在字段内获取
                if(saasMark == null || businessType== null || formId== null){
                    saasMark = fieldAttrEntity.getSaasMark();
                    businessType = fieldAttrEntity.getBusinessType();
                    formId = fieldAttrEntity.getFormId();
                }
                List<FieldAttrEntity> fieldAttrEntityList = null;
                FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldAttrEntity.getFieldType());
                //查询表过滤地址字段
                if(!Objects.equals(chartType, ChartTypeEnum.DATA_QUERY_TABLE.getCode()) && (!Objects.equals(chartAttrType, ChartAttrTypeEnum.SELECT.getIndex()) && FieldTypeEnum.ADDRESS.equals(fieldTypeEnum))){
                    if (abnormalStatusList.contains(fieldAttrEntity.getStatus())) {
                        continue;
                    }
                    fieldAttrEntityList = addressParse(fieldAttrEntity,it);
                    for(FieldAttrEntity entity :fieldAttrEntityList){
                        ChartFieldAttrPojo chartFieldAttrPojo = commonDataSourceAttrEnclosure(entity, businessType, corpid, formId);
                        chartFieldAttrPojo.setSaasMark(saasMark);
                        chartFieldAttrPojo.setBusinessType(businessType);
                        chartFieldAttrPojo.setAppId(appId);
                        dataSourceObjectVO.addFieldList(chartFieldAttrPojo);
                    }
                } else if (FieldTypeEnum.isSubFormType(fieldAttrEntity.getFieldType())){
                    //汇总字段添加已在showExplainList集合中处理，numIdList为空时跳过汇总字段处理
                    subFormAttrHandle(fieldAttrEntity, dataSourceObjectVO, null, null, businessType, saasMark, appId);
                }else{
                    ChartFieldAttrPojo chartFieldAttrPojo = new ChartFieldAttrPojo();
                    if (FieldTypeEnum.LINK_BUSINESS_SINGLE.equals(fieldTypeEnum) || FieldTypeEnum.LINK_BUSINESS_MULTI.equals(fieldTypeEnum) || FieldTypeEnum.BIRTHDAY.equals(fieldTypeEnum)) {
                        BeanUtil.copyProperties(fieldAttrEntity, chartFieldAttrPojo);
                        String linkedText = chartFieldAttrPojo.getLinkedText();
                        if(StringUtil.isNotEmpty(linkedText)){
                            FieldAttrEntity linkedAttr = explainMap.get(linkedText);
                            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(linkedAttr));
                            if (Objects.nonNull(jsonObject)){
                                jsonObject.put(StringConstant.FORM_ID, formId);
                                chartFieldAttrPojo.setLinkedAttr(jsonObject);
                            }
                        }
                    } else {
                        if(dataSetChartFlag){
                            BeanUtil.copyProperties(fieldAttrEntity,chartFieldAttrPojo);
                        }else {
                            chartFieldAttrPojo = commonDataSourceAttrEnclosure(fieldAttrEntity, businessType, corpid, formId);
                        }
                    }
                    //分组字段下时间类型默认格式yyyy-MM-dd
                    if (EsHelper.isDateTimeByFieldType(fieldAttrEntity.getFieldType()) && Objects.equals(ChartAttrTypeEnum.GROUP.getIndex(), chartAttrType)) {
                        chartFieldAttrPojo.setDateGroupType(IntervalTypeEnum.YEAR_MONTH_DAY.getDateFormat());
                    }
                    chartFieldAttrPojo.setSaasMark(saasMark);
                    chartFieldAttrPojo.setBusinessType(businessType);
                    chartFieldAttrPojo.setAppId(appId);
                    //如果是产品分类加上已选择的分类（参数）
                    if (XbbRefTypeEnum.PRODUCT.getCode() == businessType.intValue() && ProductEnum.CATEGORY_ID.getAttr().equals(chartFieldAttrPojo.getAttr()) && chartFieldAttrPojo.getSelectedCategory()==null){
                        JSONArray jsonArray=new JSONArray();
                        chartFieldAttrPojo.setSelectedCategory(jsonArray);
                    }
                    dataSourceObjectVO.addFieldList(chartFieldAttrPojo);
                }

                if (Objects.equals(fieldAttrEntity.getSaasAttr(), ContractEnum.CASH_PROFIT_RATE.getSaasAttr()) || Objects.equals(fieldAttrEntity.getSaasAttr(), ContractEnum.GROSS_PROFIT_RATE.getSaasAttr()) || Objects.equals(fieldAttrEntity.getSaasAttr(), PaasStageEnum.STAGE_RATIO.getSaasAttr())) {
                    // 利率numberType设为2
                    fieldAttrEntity.setNumberType(NumberTypeEnum.RATE.getCode());
                }

            }
        }
    }


    public void changeNameWithI18n(List<? super FieldAttrEntity> fieldList) {
        if (Objects.equals(LocaleContextHolder.getLocale().getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
            fieldList.forEach(item -> {
                FieldAttrEntity fieldAttrEntity = (FieldAttrEntity) item;
                String attrName = fieldAttrEntity.getAttrName();
                String attrNameEn = fieldAttrEntity.getAttrNameEn();
                fieldAttrEntity.setAttrName(attrName);
                fieldAttrEntity.setAttrNameEn(attrNameEn);
            });
        }
    }

    /**
     * 计算字段设置页-待选字段进行分类
     *
     * @param dataSourceObjectVO
     * @author zyy
     * @date 2023/3/1
     * @version v1.0
     */
    public void groupByFieldType(DataSourceObjectVO dataSourceObjectVO) {
        List<? super FieldAttrEntity> fieldList = dataSourceObjectVO.getFieldList();
        if(CollectionsUtil.isEmpty(fieldList)){
            return;
        }
        Map<String,List<FieldAttrEntity>> groupFiledMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<FieldAttrEntity> numFieldList = new ArrayList<>();
        List<FieldAttrEntity> dateFieldList = new ArrayList<>();
        List<FieldAttrEntity> otherFieldList = new ArrayList<>();
        for (Object o : fieldList) {
            FieldAttrEntity fieldAttrEntity = (FieldAttrEntity) o;
            Integer fieldType = fieldAttrEntity.getFieldType();
            if (FieldTypeEnum.getNumComputedType().contains(fieldType)){
                //归纳数字字段
                numFieldList.add(fieldAttrEntity);
            }else if (FieldTypeEnum.getDateComputedType().contains(fieldType)){
                //归纳日期字段
                dateFieldList.add(fieldAttrEntity);
            }else if(FieldTypeEnum.getOtherComputedType().contains(fieldType)){
                otherFieldList.add(fieldAttrEntity);
            }
        }
        groupFiledMap.put("num",numFieldList);
        groupFiledMap.put("date",dateFieldList);
        groupFiledMap.put("other",otherFieldList);
        dataSourceObjectVO.setGroupFiledMap(groupFiledMap);
    }
}
